package com.servlet.users;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDAO;
import com.entity.Users;

public class RegisterServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		
		Users users = new Users(userName,userPassword);
		UsersDAO usersDAO = new UsersDAO();

//		String msg = "失败";
//		String returnPath = "/background/saveBookInfo.jsp";
		if (usersDAO.save(users)) {
//			msg = "成功";
//			returnPath = "/FindAllBookInfoServlet";
			request.getRequestDispatcher("/registersucess.jsp").forward(request, response);
			return;
		}
		//提示消息
////		request.setAttribute("msg", "新增用户信息" + msg);
//		//返回路径
//		request.setAttribute("returnPath", returnPath);
		request.getRequestDispatcher("/register.jap").forward(request, response);

	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		
		Users users = new Users(userName,userPassword);
		UsersDAO usersDAO = new UsersDAO();
		
//		String msg = "失败";
//		String returnPath = "/background/saveBookInfo.jsp";
		if (usersDAO.save(users)) {
//			msg = "成功";
//			returnPath = "/FindAllBookInfoServlet";
			request.getRequestDispatcher("/registersucess.jsp").forward(request, response);
			return;
		}
		//提示消息
////		request.setAttribute("msg", "新增用户信息" + msg);
//		//返回路径
//		request.setAttribute("returnPath", returnPath);
		request.getRequestDispatcher("/register.jap").forward(request, response);



	}

}
